<?php
class CommentModel extends Model {
    public function getComment($mid) {
        $pre = C('db_prefix');
        $sql = 'SELECT a.*,b.nickname,b.small_img FROM '.$pre.'comment as a,'.$pre.'member_info as b where a.reply_mid=b.mid AND a.mid='.$mid.' AND a.fcid=0';
        $data = $this->query($sql);
        $sql = 'SELECT a.*,b.nickname,b.small_img FROM '.$pre.'comment as a,'.$pre.'member_info as b where a.reply_mid=b.mid AND a.mid='.$mid.' AND a.fcid!=0';
        $reply_data = $this->query($sql);
        if(is_array($data)) {
            foreach($data as $k=>$v){
                if(is_array($reply_data)) {
                    foreach($reply_data as $key=>$value){
                        if($value['fcid'] == $v['cid']) {
                            $data[$k]['reply'][]=$value;
                            unset($replay_data[$key]);
                        }
                    }
                }
            }
        }
        return $data;
    }
}